package demo;

import javax.swing.*;
import java.awt.*;

/**
 * Version: 1.1
 * Author: TangJun
 * Date: 2024-07-30
 */
public class Test extends JFrame{
    private MyPanel mp = null;
    public static void main(String[] args) {
        new Test();
    }
    public Test() {
        mp = new MyPanel();
        //将画板放到窗口
        this.add(mp);
        this.setSize(2560 / 2, 1440 / 2);
        this.setVisible(true);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    }
}

//自定义画板
class MyPanel extends JPanel {
    @Override
    public void paint(Graphics g) {

        System.out.println("paint被调用");        //g是画笔
        g.drawLine(0,200,100,200);
        g.drawOval(100, 100, 200, 100);
        g.drawRect(20,20,100,100);

        g.setColor(Color.blue);
        g.fillOval(0,0,100,100);
        g.setColor(Color.pink);
        g.fillRect(200, 200, 100, 100);

        Image image = Toolkit.getDefaultToolkit().getImage(Panel.class.getResource("/picture.jpg"));
        g.drawImage(image, 0, 0, 384 * 3, 216 * 3, this);

        g.setColor(Color.BLACK);
        g.setFont(new Font("楷体", Font.BOLD, 40));
        g.drawString("天选", 384 * 3 / 2, 100);
    }
}

